﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.mMall.Public
{
    public partial class mfTravelRoute : msBsc.Cls.mbPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        string countryId = "";
        string cityId = "";
        string destionId = "";
        private void initplace()
        {
            string parentsId = this.GetParamHtValue("parentsId");
            countryId = this.GetParamHtValue("countryId");
            cityId = this.GetParamHtValue("cityId");
            destionId = this.GetParamHtValue("destionId");
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                if (ds == null || ds.Tables[0].Rows.Count < 0)
                {
                    return;
                }
                DataRow dr = ds.Tables[0].NewRow();
                dr["COUNTRY_CITY_ID"] = "";
                dr["COUNTRY_CITY_NME"] = "全部";
                ds.Tables[0].Rows.InsertAt(dr, 0);
                if (string.IsNullOrEmpty(countryId))
                {
                    countryId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 10000, "");
                this.ExecJScript(@"$('#countryId').val('" + countryId + "');setCity(" + strJson + @",""country_select"",'" + countryId + "');");

                ds = cbcc.SelectCountryByParentId(countryId);
                if (ds == null || ds.Tables[0].Rows.Count < 0)
                {
                    return;
                }
                dr = ds.Tables[0].NewRow();
                dr["COUNTRY_CITY_ID"] = "";
                dr["COUNTRY_CITY_NME"] = "全部";
                ds.Tables[0].Rows.InsertAt(dr, 0);
                if (string.IsNullOrEmpty(cityId))
                {
                    cityId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 10000, "");
                this.ExecJScript(@"$('#cityId').val('" + cityId + "');setCity(" + strJson + @",""city_select"",'" + cityId + "');");

                ds = cbcc.SelectCountryByParentId(cityId);
                if (ds == null || ds.Tables[0].Rows.Count < 0)
                {
                    return;
                }
                dr = ds.Tables[0].NewRow();
                dr["COUNTRY_CITY_ID"] = "";
                dr["COUNTRY_CITY_NME"] = "全部";
                ds.Tables[0].Rows.InsertAt(dr, 0);
                if (string.IsNullOrEmpty(destionId))
                {
                    destionId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 10000, "");
                this.ExecJScript(@"$('#destionId').val('" + destionId + "');setCity(" + strJson + @",""destion_select"",'" + destionId + "');");
            }
        }

        /// <summary>
        /// 获取路线列表
        /// </summary>
        /// Author:任延华
        /// Creation date:2015-8-4
        private void GetRouteList()
        {
            string pIndex = this.GetParamHtValue("pIndex");
            string pRows = this.GetParamHtValue("pRows");
            string routeKey = this.GetParamHtValue("routeKey");
            using (msBsc.AppLogic.DataAlc.CBizRoute route = new AppLogic.DataAlc.CBizRoute())
            {
                int pSize = 15;
                int.TryParse(pRows, out pSize);
                int pageIndex = 1;
                int.TryParse(pIndex, out pageIndex);
                DataTable dt = route.GetRouteList(routeKey, countryId, cityId, destionId, pSize, pageIndex);
                if (dt == null || dt.Rows.Count < 1)
                {
                    return;
                }
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(dt, "", "", 1, 100, "");
                this.ExecJScript(@"var _html = $('#svc_list_temp_route').html();
                            laytpl(_html).render(" + ret + @", function (render) {
                                                $('#trvel_list').append(render);
                            });showNextPage('" + dt.Rows[0]["ROWSCOUNT"] + "')");
            }
        }
        public override void DoAction()
        {
            if (this.strAction=="init")
            {
                initplace();
                GetRouteList();
            }
            else if (this.strAction == "morePage") {
                GetRouteList();
            }
            //base.DoAction();
        }
    }
}